package ali.point;

import ali.compass.Compass;

import static ali.compass.Compass.getCompass;
import static java.lang.Math.atan;
import static java.lang.Math.pow;
import static java.lang.Math.sqrt;

/**
 * Created by IntelliJ IDEA.
 * User: aliolci
 * Date: 16/06/11
 * Time: 23:24
 * To change this template use File | Settings | File Templates.
 */
public class Point {
    private float x;
    private float y;

    private Point(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public static Point point(float x, float y){
        return new Point((int)x, (int)y);
    }

    public static Point point(int x, int y){
        return new Point(x, y);
    }

    public int getX() {
        return (int)x;
    }

    public int getY() {
        return (int)y;
    }

    public float getXf() {
        return x;
    }

    public float getYf() {
        return y;
    }

    public float getDistance(Point toThisPoint){
        return (float) sqrt(pow(this.getXf()-toThisPoint.getXf(),2)+pow(this.getYf()-toThisPoint.getYf(),2));
    }

    public Compass getPositionOf(Point parameterPointToThisPoint){
        return getCompass(this, parameterPointToThisPoint);
    }

    public double getInclineBetweenThisPointAnd(Point parameterPoint){
        return atan((this.getYf() - parameterPoint.getYf()) / (this.getXf() - parameterPoint.getXf()));
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Point point = (Point) o;

        if (Float.compare(point.x, x) != 0) return false;
        if (Float.compare(point.y, y) != 0) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = (x != +0.0f ? Float.floatToIntBits(x) : 0);
        result = 31 * result + (y != +0.0f ? Float.floatToIntBits(y) : 0);
        return result;
    }
}
